//
//  LXHomeButtonViewCell.m
//  LvXiShopping
//
//  Created by 诸葛孔明 on 16/5/27.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "LXHomeButtonViewCell.h"

#import "LXHomeButton.h"

#import "LXWebViewController.h"

#import "SignViewController.h"

#import "LXMallShareController.h"

#import "CategoryViewController.h"

@interface LXHomeButtonViewCell()

@property(nonatomic,strong)NSArray *imageArray;
@property(nonatomic,strong)NSArray *titles;

@end

@implementation LXHomeButtonViewCell
- (NSArray *)imageArray
{
    if (!_imageArray) {
        _imageArray = @[@"home_but_green",@"home_but_wine",@"but_sign_n"];
    }
    return _imageArray;
}

- (NSArray *)titles
{
    if (!_titles) {
        _titles = @[@"营养保健",@"酒水茶饮",@"每日签到"];
    }
    return _titles;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    NSInteger count = self.imageArray.count;
    
    CGFloat X = 10;
    CGFloat Y = 0;
    CGFloat W = ([UIScreen mainScreen].bounds.size.width - 120)/ count;
    CGFloat H = W+20;
    
    for (int i = 0; i < count; i ++) {
        LXHomeButton *button = [[LXHomeButton alloc] init];
        X = i * W + 10;
        button.frame = CGRectMake(X, Y, W, H);
        
        button.tag = i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:self.imageArray[i]] forState:UIControlStateNormal];
        [button setTitle:self.titles[i] forState:UIControlStateNormal];
        [self addSubview:button];
    }
    self.cellHeight = H;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        self.contentView.backgroundColor = [UIColor whiteColor];
        NSInteger count = self.imageArray.count;
        CGFloat space = 40;
        CGFloat X = 0;
        CGFloat Y = 0;
        CGFloat W = ([UIScreen mainScreen].bounds.size.width - space*(count+1))/ count;
        CGFloat H = W+30;
        for (int i = 0; i < count; i ++) {
            LXHomeButton *button = [[LXHomeButton alloc] init];
            X = i * (W+space) + space;
            button.frame = CGRectMake(X, Y, W, H);
            button.tag = i;
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [button setImage:[UIImage imageNamed:self.imageArray[i]] forState:UIControlStateNormal];
            [button setTitle:self.titles[i] forState:UIControlStateNormal];
            
            [self addSubview:button];
        }
        
        self.cellHeight = H;
    }
    return self;
}

- (void)buttonClick:(LXHomeButton *)button
{
    [self jumpWithButton:button];
}

-(void)jumpWithButton:(UIButton*)button
{
    NSString * cat_id = nil;
    if([button.currentTitle isEqualToString:@"每日签到"]){
        
    }
    else if([button.currentTitle isEqualToString:@"营养保健"]){
        cat_id = @"163";
    }
    else if ([button.currentTitle isEqualToString:@"酒水茶饮"]){
        cat_id = @"164";
    }
    else{
       
    }
    if(self.handleEnevts){
        self.handleEnevts(cat_id);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    //[super setSelected:selected animated:animated];

    
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    
}

@end
